package com.atfzr.CAS;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 望夜
 * @description
 * @date 2023/8/24---20:32
 */
public class CASDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5); //第一次匹配5成功，第二次被修改为2022匹配失败
        System.out.println(atomicInteger.compareAndSet(5, 2022) + "\t" + atomicInteger.get());//true	2022
        System.out.println(atomicInteger.compareAndSet(5, 2022) + "\t" + atomicInteger.get());//false	2022
    }
}
